﻿<%@ Assembly Name="$SharePoint.Project.AssemblyFullName$" %>
<%@ Assembly Name="Microsoft.Web.CommandUI, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> 
<%@ Register Tagprefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register Tagprefix="asp" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %>
<%@ Import Namespace="Microsoft.SharePoint" %> 
<%@ Register Tagprefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=14.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ViewAllAlbumsUserControl.ascx.cs" Inherits="JM.JCY.SharePointComponent.PhotoAlbum.ViewAllAlbums.ViewAllAlbumsUserControl" %>

<script type="text/javascript">
    function RedirectToHome(sender) {
        
        var wc = $("#<%=HiddenFieldWC.ClientID %>").val();
        if (wc == "T") {
            sender.href = "ViewObjectAlbums.aspx?Type=" + getArgs("Type") + "&appid=" + getArgs("appid");
        } else {
            sender.href = "AlbumCategories.aspx";
        }
    }

    function getArgs(strParame) {
        var args = new Object();
        var query = location.search.substring(1);
        var pairs = query.split("&");
        for (var i = 0; i < pairs.length; i++) {
            var pos = pairs[i].indexOf('=');
            if (pos == -1) continue;
            var argname = pairs[i].substring(0, pos);
            var value = pairs[i].substring(pos + 1);
            args[argname] = value;
        }
        return args[strParame];
    }

    function RedirectToAddAlbum(sender) {
        sender.href = "AddAlbum.aspx";
    }

    function RedirectToViewAlbum(sender, albumId) {
        sender.href = "ViewAlbum.aspx?AlbumId=" + albumId;
    }

    function RedirectToStaffProfile(sender, staffId) {
        sender.href = "/PersonalSite/PersonalPages/PublicUser.aspx?StaffId=" + staffId;
    }

    $(document).ready(function () {
        SetCurrentLink(1);
        Showpagination();
    });

    function turnPage(pageIndex) {
        $("#currIndex").val(pageIndex);
        SetCurrentLink(pageIndex);
        CallServer(pageIndex, 'content');
    }

    function turnPagePrev() {
        var prevIndex = parseInt($("#currIndex").val());
        var currentIndex = 1;
        if (prevIndex > 1)
            currentIndex = prevIndex - 1;
        $("#currIndex").val(currentIndex);
        SetCurrentLink(currentIndex);
        CallServer(currentIndex, 'content');
    }

    function turnPageNext() {
        var prevIndex = parseInt($("#currIndex").val());
        var currentIndex = $("#lastIndex").val();
        if (prevIndex < $("#lastIndex").val())
            currentIndex = prevIndex + 1;
        $("#currIndex").val(currentIndex);
        SetCurrentLink(currentIndex);
        CallServer(currentIndex, 'content');
    }

    function turnPageLast() {
        var currentIndex = $("#lastIndex").val();
        $("#currIndex").val(currentIndex);
        SetCurrentLink(currentIndex);
        CallServer(currentIndex, 'content');
    }

    function ReceiveCallback(arg, context) {
        var container = document.getElementById(context);
        container.innerHTML = arg;
    }

    function SetCurrentLink(currentIndex) {
        var lastIndex = $("#lastIndex").val();
        var i;
        for (i = 1; i <= lastIndex; i++) {
            if (i == currentIndex)
                $("#a" + i).css('text-decoration', 'underline');
            else
                $("#a" + i).css('text-decoration', 'none');
        }

        //Set First,Previous,Next, Last button enable or disable
        if (currentIndex == 1) {
            $("#lbFirst").attr("disabled", "true");
            $("#lbPrev").attr("disabled", "true");
        }
        else {
            $("#lbFirst").removeAttr("disabled");
            $("#lbPrev").removeAttr("disabled");
        }

        if (currentIndex == lastIndex) {
            $("#lbNext").attr("disabled", "true");
            $("#lbLast").attr("disabled", "true");
        }
        else {
            $("#lbNext").removeAttr("disabled");
            $("#lbLast").removeAttr("disabled");
        }
    }

    function ResizeImage(sender) {
        var image = new Image();
        image.src = sender.src;
        if (image.width > 0 && image.height > 0) {
            var height = image.height;
            var width = image.width;
            if (parseInt(width) / parseInt(height) >= 159 / 126) {
                sender.style.height = 126;
            }
        }
    }

    function Showpagination() {
        var pageNum = parseInt($("#<%=HiddenFieldPageNum.ClientID %>").val());
        if (pageNum == 1 || pageNum == 0) {
            $("div.pagination").css("display", "none");
            $("#backhome").css("display", "block");
            $("#backhome").addClass("pagination");
        }
    }
</script>
<style type="text/css">
    #background
    {
        z-index: -1;
        border: 1px solid #B8B8B8;
        width: 167px;
        height: 134px;
    }
    #imagebox
    {
        border: 1px solid #B8B8B8;
        margin-left: 4px;
        margin-top: 4px;
        width: 159px;
        height: 126px;
        background-color: #ffffff;
        padding: 4px;
        border-bottom: 1px solid #B8B8B8;
    }
    #containerImg
    {
        width: 159px;
        height: 126px;
        padding: 0px;
        overflow: hidden;
        float: none;
    }
</style>
<div>
    <table class="main" width="100%" cellpadding="0" cellspacing="0" border="0">
        <tr>
            <td valign="top" width="100%">
                <table class="content" width="99%">
                    <tr>
                        <td>
                            <div class="gallery">
                                <table width="100%" class="galleryTitle">
                                    <tr>
                                        <td width="60%">
                                            <h2 class="gallery">
                                                <asp:Image ID="Image1" runat="server" ImageUrl="/_layouts/JM.JCY.Resource/images/相册小.png" />
                                                相册
                                            </h2>
                                        </td>
                                        <td align="right" width="40%" class="link">
                                                 <img src="/_layouts/JM.JCY.Resource/images/plus.png" width="12"/>
                                            <asp:LinkButton ID="lbCreateAlbum" runat="server" class="galleryDetail" OnClientClick="RedirectToAddAlbum(this)">创建相册</asp:LinkButton>
                                        </td>
                                    </tr>
                                    <tr>
                                    <td colspan="2">
                                    <br />
                                    <hr />
                                    </td>
                                    </tr>
                                    <tr nowrap="nowrap">
                                        <td colspan="2" align="right">
                                            <div id="backhome" style="display: none">
                                              <img src="/_layouts/JM.JCY.Resource/images/back_link.png" id="lbBackHomeimg2" width="12"/>
                                                <asp:LinkButton ID="lbBackHome2" runat="server" CssClass="link" OnClientClick="RedirectToHome(this)">返回相册中心</asp:LinkButton>
                                            </div>
                                            <div class="pagination">
                                                     <img src="/_layouts/JM.JCY.Resource/images/back_link.png" id="lbBackHomeimg" width="12"/>
                                                <asp:LinkButton ID="lbBackHome" runat="server" Font-Size="12px" OnClientClick="RedirectToHome(this)">返回相册中心</asp:LinkButton>
                                                &nbsp;&nbsp;
                                                <asp:LinkButton ID="lbFirst" runat="server" Text="<< 第一页" class="galleryDetailOfpagination"
                                                    OnClientClick="turnPage(1);return false;"></asp:LinkButton>
                                                <asp:Label ID="lbl1" runat="server" Text="|"></asp:Label>
                                                <asp:LinkButton ID="lbPrev" runat="server" Text="< 上一页" class="galleryDetailOfpagination"
                                                    OnClientClick='turnPagePrev();return false;'></asp:LinkButton>
                                                <asp:Label ID="lbl2" runat="server" Text="|"></asp:Label>
                                                <asp:LinkButton ID="lbNext" runat="server" Text="下一页 >" class="galleryDetailOfpagination"
                                                    OnClientClick='turnPageNext();return false;'></asp:LinkButton>
                                                <asp:Label ID="lbl3" runat="server" Text="|"></asp:Label>
                                                <asp:LinkButton ID="lbLast" runat="server" Text="最后一页 >>" class="galleryDetailOfpagination"
                                                    OnClientClick='turnPageLast();return false;'></asp:LinkButton>
                                                <input id="currIndex" type="text" value="1" style="display: none;" />
                                                <input id="lastIndex" type="text" value="<%=lastIndex%>" style="display: none;" />
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                                <br />
                                <table class="galleryHeader" width="100%">
                                    <tr>
                                        <td width="70%">
                                            <asp:Label ID="lblTitle" runat="server" Text="所有相册 - 最新更新"></asp:Label>
                                        </td>
                                        <td width="30%" align="right">
                                            &nbsp;
                                        </td>
                                    </tr>
                                </table>
                                <table width="100%" class="photoAlbum">
                                    <tr>
                                        <td>
                                            <div id="content">
                                                <asp:DataList ID="dlResult" runat="server" RepeatColumns="5" OnItemDataBound="DataList_ItemDataBound"
                                                    RepeatDirection="Horizontal">
                                                    <ItemTemplate>
                                                        <div>
                                                            <table width="100%" style="margin-bottom: 20px">
                                                                <tr>
                                                                    <td>
                                                                        <div class="ThumbNailImg">
                                                                            <div id="background">
                                                                                <div id="imagebox">
                                                                                    <div id="containerImg">
                                                                                        <a id="img" href="#" onclick="RedirectToViewAlbum(this,'<%# Eval("AlbumId") %>')">
                                                                                            <img id="imgThumbNail" src='<%# Eval("ThumbNailImgUrl") %>' width="159" height="126"
                                                                                                class="photoAlbum" alt='<%# Eval("Description") %>' onload="ResizeImage(this);" />
                                                                                        </a>
                                                                                    </div>
                                                                                </div>
                                                                            </div>
                                                                        </div>
                                                                    </td>
                                                                </tr>
                                                                <tr>
                                                                    <td>
                                                                        <table width="100%">
                                                                            <tr>
                                                                                <td colspan="2">
                                                                                    <asp:LinkButton ID="lbAlbumName" CssClass="link" runat="server" Text='<%# Eval("Name") %>'
                                                                                        OnClientClick='<%# String.Format("RedirectToViewAlbum({0},{1})","this",Eval("AlbumId")) %>'
                                                                                        ToolTip='<%# Eval("Name") %>'></asp:LinkButton>
                                                                                </td>
                                                                            </tr>
                                                                            <tr>
                                                                                <td colspan="2">
                                                                                    <asp:Label ID="lblBy" CssClass="gallery" runat="server" Text="相册创建人："></asp:Label>
                                                                                    <asp:LinkButton ID="lbCreateBy" CssClass="link" runat="server" Text='<%# Eval("AlbumOwner") %>'
                                                                                        ToolTip='<%# Eval("AlbumOwner") %>' OnClientClick='<%# String.Format("RedirectToStaffProfile({0},{1})","this",Eval("Creator")) %>'></asp:LinkButton>
                                                                                </td>
                                                                            </tr>
                                                                            <tr runat="server" id="trDetail">
                                                                                <td nowrap="nowrap" style="width: 90px;">
                                                                                    <asp:Label ID="lblMediaCount" CssClass="gallery" runat="server" Text='<%# Eval("ItemCount") %>'></asp:Label>
                                                                                    <asp:Label ID="lblMedia" CssClass="gallery" runat="server" Text="照片"></asp:Label>
                                                                                    <asp:Image ID="imgLike" runat="server" ImageUrl="/_layouts/JM.JCY.Resource/images/thumbs-up.gif" />
                                                                                    <asp:Label ID="lblLikeCount" CssClass="gallery" runat="server" Text='<%# Eval("LikeCount") %>'></asp:Label>
                                                                                </td>
                                                                                <td>
                                                                                    &nbsp;
                                                                                </td>
                                                                            </tr>
                                                                        </table>
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                        </div>
                                                    </ItemTemplate>
                                                </asp:DataList>
                                            </div>
                                        </td>
                                    </tr>
                                </table>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td align="right">
                            <div class="pagination">
                                <asp:LinkButton ID="lbFirst1" runat="server" Text="<< 第一页" class="galleryDetailOfpagination"
                                    OnClientClick="turnPage(1);return false;"></asp:LinkButton>
                                <asp:Label ID="lbl4" runat="server" Text="|"></asp:Label>
                                <asp:LinkButton ID="lbPrev1" runat="server" Text="< 上一页" class="galleryDetailOfpagination"
                                    OnClientClick='turnPagePrev();return false;'></asp:LinkButton>
                                <asp:Label ID="lbl5" runat="server" Text="|"></asp:Label>
                                <asp:LinkButton ID="lbNext1" runat="server" Text="下一页 >" class="galleryDetailOfpagination"
                                    OnClientClick='turnPageNext();return false;'></asp:LinkButton>
                                <asp:Label ID="lbl6" runat="server" Text="|"></asp:Label>
                                <asp:LinkButton ID="lbLast1" runat="server" Text="最后一页 >>" class="galleryDetailOfpagination"
                                    OnClientClick='turnPageLast();return false;'></asp:LinkButton>
                            </div>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
<asp:HiddenField ID="HiddenFieldPageNum" runat="server" />
<asp:HiddenField ID="HiddenFieldWC" runat="server" />
</div>